package com.java.module.cms.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.cms.domain.About;
import com.java.module.cms.service.IAboutService;

/**
 * 单篇图文Controller
 *
 * @author Administrator
 * @date 2021-02-02
 */
@RestController("AdminAboutController")
@RequestMapping("/cms/about")
public class AboutController {

    @Autowired
    private IAboutService aboutService;

    /**
     * 查询单篇图文列表
     */
    @PreAuthorize("@ss.hasPermi('cms:about:list')")
    @GetMapping("/list")
    public TableDataInfo list(About about) {
        WebKit.startPage();
        List<About> list = aboutService.selectAboutList(about);
        return WebKit.getDataTable(list);
    }

    /**
     * 获取单篇图文详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:about:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(aboutService.selectAboutById(id));
    }

    /**
     * 新增单篇图文
     */
    @PreAuthorize("@ss.hasPermi('cms:about:add')")
    @Log(title = "单篇图文", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody About about) {
        return aboutService.insertAbout(about);
    }

    /**
     * 修改单篇图文
     */
    @PreAuthorize("@ss.hasPermi('cms:about:edit')")
    @Log(title = "单篇图文", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody About about) {
        return WebKit.toAjax(aboutService.updateAbout(about));
    }

}